package com.xn.myyxcampus.adapter;

import com.xn.myyxcampus.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MenuAdapter extends BaseAdapter {

	private int[] menuImg;
	private String[] menuItem;
	private Context context;

	public MenuAdapter(Context context, int[] menuImg, String[] menuItem) {
		this.context = context;
		this.menuItem = menuItem;
		this.menuImg = menuImg;
	}

	public void setMneuImg(int[] menuImg) {
		this.menuImg = menuImg;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return menuItem.length;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder;
		if (null == convertView) {
			convertView = LayoutInflater.from(context).inflate(
					R.layout.menu_item, null);
			holder = new ViewHolder();
			holder.iv_menu = (ImageView) convertView.findViewById(R.id.iv_menu);
			holder.tv_menu = (TextView) convertView.findViewById(R.id.tv_menu);
			convertView.setTag(holder);

		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.iv_menu.setImageResource(menuImg[position]);

		holder.tv_menu.setText(menuItem[position]);
		return convertView;
	}

	class ViewHolder {
		ImageView iv_menu;
		TextView tv_menu;
	}
}
